﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;
using AjaxPro;
using Gift.Model;
using Gift.DAL;



namespace WebSite.cn
{
    public partial class head : System.Web.UI.UserControl
    {

        readonly DALGoodsType theGoodsType = new DALGoodsType();
        readonly MemberAccount theMemberAccount = new MemberAccount();
        tbGoodsType oGoodsType;
  readonly BasePage theBase = new BasePage();
  readonly DALCar theCar = new DALCar();

    public string lan = "";
    public string logo = "";
    public string shop = "0";
    public string shopname = "";
    public string shopurl = "";
    public StringBuilder sbTopic = new StringBuilder();
    public string totalprice = "0";
    public string typemsg = "";

    string _displayTop = "display:none;";

     string sMenuFormat = "<div class=\"mainNavLevel none\"> "
                         +" <div class=\"mainNavList\">"
                          +"<ul>{0}"
                            +"</ul>"
                          +" </div>"
                            +"  <div class=\"mainNavPic\">"
                            +"  <a href=\"{1}\" target=\"_blank\"><img src=\"/uploadfile/product/{2}\"></a>"
                           +" </div>"
                           +" </div>";

    StringBuilder _sbCardProfession = new StringBuilder();
    StringBuilder _sbGoodsProfession = new StringBuilder();
    StringBuilder _sbTimeBuy = new StringBuilder();

    public StringBuilder SbCardProfession
    {
        get { return _sbCardProfession; }
    }

    public StringBuilder SbGoodsProfession
    {
        get { return _sbGoodsProfession; }
    }

    public StringBuilder SbTimeBuy
    {
        get { return _sbTimeBuy; }
    }

    public string DefaultPageView = "menu01";
    public string CardPageView = "menu02";
    public string GoodsPageView = "menu02";
    public string RushintPageView = "menu02";
    public string MyPointsBoxPageView = "menu02";
    public string PointsExchangeView = "menu02";
    public string CompanyPartnerPageView = "menu02";
    public string BlogPageView = "menu02";


    void BindMenuView()
    {
        if (Request.Path.Contains("index."))
        {
            DefaultPageView = "menu01over";
        }
        else if (Request.Path.Contains("hotpro."))
        {
            if (! string.IsNullOrEmpty(Request.QueryString["tid"]))
            {
                oGoodsType = theGoodsType.GetModel(int.Parse(Request.QueryString["tid"]));
                if (oGoodsType != null)
                {
                    if(oGoodsType.typeName == "卡券专区")
                    {
                        CardPageView = "menu02over";
                    }
                    else if (oGoodsType.typeName == "产品专区")
                    {
                        GoodsPageView = "menu02over";
                    }
                }
            }
          
        }
        else if (Request.Path.Contains("rushing."))
        {
            RushintPageView = "menu02over";
        }
        else if (Request.Path.Contains("userinfo.aspx"))
        {
            MyPointsBoxPageView = "menu02over";
        }
        else if (Request.Path.Contains("exchangeGoods.aspx"))
        {
            PointsExchangeView = "menu02over";
        }
        else if (Request.Path.Contains("partner."))
        {
            CompanyPartnerPageView = "menu02over";
        }
        else if (Request.Path.Contains("blog.") || Request.Path.Contains("cn/Articles"))
        {
            BlogPageView = "menu02over";
        }

    }




    public string DisplayTop
    {
        get {
            if (!Request.Path.Contains("index.aspx"))
            {
                _displayTop = "display:none;";
            }
            return _displayTop; }
      
    }

    StringBuilder _sbCarInfo = new StringBuilder();

    public StringBuilder SbCarInfo
    {
        get { return _sbCarInfo; }
    }



    public StringBuilder sbHeadMenu = new StringBuilder();




    public BasePage TheBasePage
    {
        get
        {
            return new BasePage();
        }
    }



    protected void Page_Load(object sender, EventArgs e)
    {
       // Utility.RegisterTypeForAjax(typeof(WebSite.Code.MemberCardInfo_ajax));
        if (!IsPostBack)
        {
           
            // this.Bind();
            this.BindCarInfo();
            this.BindSuMenu();
            this.BindMenuView();
        }
    }

    void BindCarInfo()
    {
        if (theBase.LoginUserMember != null)
        {
            _sbCarInfo.Append("<a class=\"car\" href=\"/cn/account.aspx\">去结算</a>");
        }
        else
        {
            _sbCarInfo.Append("<a class=\"thickbox car\" href=\"/cn/accountLogin.aspx?TB_iframe=true&height=370&width=640\">去结算</a>");
        }
    }

    void BindSuMenu()
    {
        string sLiFormat = "<li><A href=\"{0}\" target='_self'>{1}</a></li>";
        DataTable table = theGoodsType.GetMainMenuList("卡券专区").Tables[0];
        table.DefaultView.RowFilter = "typeName<>'卡券专区'";
        StringBuilder sbCardSub = new StringBuilder();
        DataView  dView = table.DefaultView;
       
        for(int i=0;i<dView.Count;i++)
        {
            oGoodsType = theGoodsType.GetModel(int.Parse(dView[i]["typeId"].ToString()));
            sbCardSub.AppendFormat(sLiFormat
                , dView[i]["typeLink"].ToString() == "" ? "/cn/hotpro.aspx?tid=" + oGoodsType.parentId.ToString() + "&subid=" + dView[i]["typeId"].ToString() : dView[i]["typeLink"].ToString()
                                    ,dView[i]["typeName"].ToString()
                                    );
        }
       table.DefaultView.RowFilter = "typeName='卡券专区'";
        dView = table.DefaultView;
      
        for(int i=0;i<dView.Count;i++)
        {
            _sbCardProfession.AppendFormat(sMenuFormat
                                   , sbCardSub.ToString()
                                    ,dView[i]["typeLink"].ToString()
                                    ,dView[i]["typePic"].ToString()
                                    );
        }


        table = theGoodsType.GetMainMenuList("产品专区").Tables[0];
        table.DefaultView.RowFilter = "typeName<>'产品专区'";
        sbCardSub = new StringBuilder();
         dView = table.DefaultView;

        for (int i = 0; i < dView.Count; i++)
        {
            oGoodsType = theGoodsType.GetModel(int.Parse(dView[i]["typeId"].ToString()));
            sbCardSub.AppendFormat(sLiFormat
                                    , dView[i]["typeLink"].ToString() == "" ? "/cn/hotpro.aspx?tid=" + oGoodsType.parentId.ToString() + "&subid=" + dView[i]["typeId"].ToString() : dView[i]["typeLink"].ToString()
                                    , dView[i]["typeName"].ToString()
                                    );
        }
        table.DefaultView.RowFilter = "typeName='产品专区'";
        dView = table.DefaultView;

        for (int i = 0; i < dView.Count; i++)
        {
            this._sbGoodsProfession.AppendFormat(sMenuFormat
                                     , sbCardSub.ToString()
                                     , dView[i]["typeLink"].ToString()
                                     , dView[i]["typePic"].ToString()
                                     );
        }


        table = theGoodsType.GetMainMenuList("限时抢购").Tables[0];
        table.DefaultView.RowFilter = "typeName<>'限时抢购'";
        sbCardSub = new StringBuilder();
        dView = table.DefaultView;

        for (int i = 0; i < dView.Count; i++)
        {
            oGoodsType = theGoodsType.GetModel(int.Parse(dView[i]["typeId"].ToString()));
            sbCardSub.AppendFormat(sLiFormat
                                         , dView[i]["typeLink"].ToString() == "" ? "/cn/hotpro.aspx?tid=" + oGoodsType.parentId.ToString() + "&subid=" + dView[i]["typeId"].ToString() : dView[i]["typeLink"].ToString()
                                    , dView[i]["typeName"].ToString()
                                    );
        }
        table.DefaultView.RowFilter = "typeName='限时抢购'";
        dView = table.DefaultView;

        for (int i = 0; i < dView.Count; i++)
        {
            this._sbTimeBuy.AppendFormat(sMenuFormat
                                     , sbCardSub.ToString()
                                      , dView[i]["typeLink"].ToString()
                                      , dView[i]["typePic"].ToString()
                                      );
        }

    }





}

}